package cn.lystudio.rohmtimeopwide_background_v11.controller.appApi;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.util.SaResult;
import cn.hutool.core.util.ObjectUtil;
import cn.lystudio.rohmtimeopwide_background_v11.entity.po.ShiftCapacityRecordPO;
import cn.lystudio.rohmtimeopwide_background_v11.service.ShiftCapacityRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/app-api/shiftcaparecord")
@CrossOrigin
@SaIgnore
@Slf4j
public class AppShiftCapacityRecordController {
    private ShiftCapacityRecordService shiftCapacityRecordService;
    @Autowired
    public void setShiftCapacityRecordService(ShiftCapacityRecordService shiftCapacityRecordService) {
        this.shiftCapacityRecordService = shiftCapacityRecordService;
    }

    @GetMapping("/getShiftCapaRecordTimeLine")
    public SaResult getShiftCapaRecordTimeLine(String machineNo, String beginDate, String endDate){

        return SaResult.data(shiftCapacityRecordService.getShiftCapaRecordTimeLine(machineNo,beginDate,endDate));
    }

    @PostMapping("/insertShiftCapacityRecord")
    public SaResult insertShiftCapacityRecord(@RequestBody ShiftCapacityRecordPO shiftCapacityRecordPO){
        int res = shiftCapacityRecordService.addShiftCapacityRecord(shiftCapacityRecordPO);
        if(res<1) return SaResult.error("添加失败");
        return SaResult.ok();
    }
    @GetMapping("/getShiftCapacityRecordByID")
    public SaResult getShiftCapacityRecordByID(int shiftCapaRecordID) {
        ShiftCapacityRecordPO shiftCapacityRecord = shiftCapacityRecordService.getShiftCapacityRecordByID(shiftCapaRecordID);
        if(ObjectUtil.isEmpty(shiftCapacityRecord)) return SaResult.error("获取数据异常");
        return SaResult.data(shiftCapacityRecord);
    }
    @PostMapping("/delShiftCapacityRecord")
    public SaResult delShiftCapacityRecord(@RequestBody ShiftCapacityRecordPO shiftCapacityRecord){
        int res = shiftCapacityRecordService.delShiftCapacityRecord(shiftCapacityRecord.getShiftCapaRecordID());
        if(res<1) return SaResult.error("删除失败");
        return SaResult.ok();
    }
    @PostMapping("/uptShiftCapacityRecord")
    public SaResult uptShiftCapacityRecord(@RequestBody ShiftCapacityRecordPO shiftCapacityRecord){
        int res = shiftCapacityRecordService.uptShiftCapacityRecord(shiftCapacityRecord);
        if(res<1){
            return SaResult.error("修改时发生错误");
        }
        return SaResult.ok();
    }
}
